#define _TEMP_CTR_MODULE_

#include "temp_ctr.h"
#include "pincfg.h"
#include "systask.h"

#include "board.h"
#include "fsl_gpio.h"
#include "clock_config.h"
#include "pin_mux.h"

#include "fsl_ctimer.h"

#include "dataproc.h"
#include "osObjects.h" 
#include "pid.h"

void simulink_run(void);
PID_Type tpid;

void temp_task(void   *argument)
{
    sysst.pid.ps.p = 200;
    sysst.pid.ps.i = 240;
    sysst.pid.ps.d = 180;
    sysst.pid.ps.r = 100;
    sysst.pid.ps.t = 3;
    
    sysst.temp_sv = 600;
    
    for(;;)
    {
        tpid.P = sysst.pid.ps.p;
        tpid.I = sysst.pid.ps.i;
        tpid.D = sysst.pid.ps.d;
        tpid.AR = sysst.pid.ps.r;
        tpid.Kt = sysst.pid.ps.t;
        
        tpid.Pv = sysst.par.ps.temp_rd;
        tpid.Sv = sysst.temp_sv;
        
        tpid.outFac = 1.0f;
        tpid.outFac_offs = 0;
        
        if(sysst.b_run_st)
        {
            osDelay(sysst.pid.ps.t*500);
            IndPid(&tpid);
        }
        else
        {
            PidClr(&tpid);
        }
        
        sysst.par.ps.t_out_period = 1000;
        sysst.par.ps.t_out_duty = tpid.Out;
        
        simulink_run();
        
        osDelay(10);
    }
}
